﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebCamView.Web.Code
{
    public class CamRepository
    {
        private Dictionary<MetaCamInfo, ImageData> currentCameras = new Dictionary<MetaCamInfo, ImageData>();
        
        public void RegisterCam(MetaCamInfo info)
        {
            currentCameras.Add(info, null);
        }

        /*public void UpdateCamInfo(MetaCamInfo info)
        {
            var infoLocal = GetByName(info.Name);
            infoLocal.MaxResolutionHeight = info.MaxResolutionHeight;
            infoLocal.MaxResolutionWidth = info.MaxResolutionWidth;
            infoLocal.FpsRate = info.FpsRate;
        }*/

        public MetaCamInfo [] GetCameras()
        {
            return currentCameras.Keys.ToArray();
        }

        /*public MetaCamInfo GetByName(string guid)
        {
            return currentCameras.First((info) => {
                return info.Key.Name == guid;
            }).Key;
        }*/

        private MetaCamInfo Find(MetaCamInfo info)
        {
            return currentCameras.Keys.FirstOrDefault((key) => { return key.Equals(info); });
        }

        public bool IsExist(MetaCamInfo info)
        {
            return this.Find(info) != null;
        }

        public void SaveImage(MetaCamInfo info, ImageData image)
        {
            currentCameras[Find(info)] = image;
        }

        public ImageData GetImage(MetaCamInfo info)
        {
            return currentCameras[Find(info)];
        }
    }
}